import React, { Component } from 'react';
import {render} from 'react-dom';

class Clock extends React.Component {
  constructor(props) {
    super(props);
    this.state = { time: new Date().toLocaleTimeString() };
  }

  componentDidMount() {
    this.timerID = setInterval(() => this.updateTime(), 1000);
  }

  updateTime(){
    this.setState({
      time : new Date().toLocaleTimeString()
    });
  }

  componentWillUnmount(){
      clearInterval(this.timerID);
  }

  render() {
    return (
      <div>
        当前时间: {this.state.time}
      </div>
    );
  }
}

//export default Clock;

render(<Clock />, document.getElementById('root'));